<template>
    <div class="module-body">
        <el-form ref="form" :model="sizeForm" label-width="80px" size="small">
            <el-form-item label="文章标题ssss">
                <el-input v-model="sizeForm.name" placeholder="请输入内容"  style="width:300px"></el-input>
            </el-form-item>
            <el-form-item label="文章类型">
                <el-select v-model="sizeForm.region" placeholder="请选择活动区域"  style="width:300px">
                <el-option label="文章" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="文章封面">
              <!-- action="http://inroferapi.sditem.com/api/upload" -->
                <el-upload
                    class="avatar-uploader"
                    action="http://inroferapi.sditem.com/api/upload"
                    :show-file-list="false"
                    :on-success="handleAvatarSuccess"
                    :before-upload="beforeAvatarUpload">
                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            <el-form-item label="文章标签"  style="width:300px">
              <el-select
                v-model="value10"
                multiple
                filterable
                allow-create
                default-first-option
                placeholder="请选择文章标签">
                <el-option
                  v-for="item in options5"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="文章内容">
               <textarea id="editor"></textarea>
            </el-form-item>
            <el-form-item label="是否发布">
                <el-radio-group v-model="sizeForm.resource" size="mini">
                <el-radio  label="显示"></el-radio>
                <el-radio  label="不显示"></el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item size="large">
                <el-button type="primary" @click="onSubmit">立即创建</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import SimpleMDE from 'simplemde'

export default {
    name: 'articleEdit',
     data() {
      return {
        sizeForm: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        imageUrl: '',
        options5: [{
          value: 'HTML',
          label: 'HTML'
        }, {
          value: 'CSS',
          label: 'CSS'
        }, {
          value: 'JavaScript',
          label: 'JavaScript'
        }],
         value10: []
        
      };
    },
    mounted() {
      const simplemde = new SimpleMDE({
        element: document.getElementById("editor") 
      })
    },
    methods: {
     onSubmit() {
        console.log('submit!');
      },
      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        // const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        // if (!isJPG ) {
        //   this.$message.error('上传头像图片只能是 JPG 格式!');
        // }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        // return isJPG && isLt2M;
        return isLt2M;
      }
    }
 
}
</script>

<style> 

.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 300px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 300px;
    height: 178px;
    display: block;
  }
</style>ß
